/******************************************************************************
*	platform/none/byteorder.h
*	 by Alex Chadwick
*
*	A light weight implementation of the USB protocol stack fit for a simple
*	driver.
*
*	platform/none/byteorder.h contains generic definitions for changing the
*	byte order of halfs to match the processor.
******************************************************************************/
#ifndef _PLATFORM_NONE_BYTEORDER_H
#define _PLATFORM_NONE_BYTEORDER_H

//------------------------------------------------------------------------------
// These macros convert between host-byte-order and specified-byte-order
//   EndianBigHalf    - Convert a 16bit half-word to/from big-endian    format
//   EndianLittleHalf - Convert a 16bit half-word to/from little-endian format
//   EndianBigWord    - Convert a 32bit word      to/from big-endian    format
//   EndianLittleWord - Convert a 32bit word      to/from little-endian format
//
#define SWAP16  ({ u16 t = x; (t >> 8) & 0xff | (t << 8) & 0xff00; })

#define SWAP32  ({ u32 t = x; (t >> 24) & 0xff     | (t >>  8) & 0xff00 |  \
                              (t <<  8) & 0xff0000 | (t << 24) & 0xff000000; })

#if defined ENDIAN_BIG
#	define EndianBigHalf(x)     x
#	define EndianBigWord(x)     x
#	define EndianLittleHalf(x)  SWAP16
#	define EndianLittleWord(x)  SWAP32
#elif defined ENDIAN_LITTLE
#	define EndianBigHalf(x)     SWAP16
#	define EndianBigWord(x)     SWAP32
#	define EndianLittleHalf(x)  x
#	define EndianLittleWord(x)  x
#else
#	error Endianness not specified.
#endif // ENDIAN_*

#endif // _PLATFORM_NONE_BYTEORDER_H
